/* GUI CONVERTED from ecimppro.p (converter v1.76) Tue Dec 31 10:45:10 2002 */
/* ecimppro.p - PCO IMPLEMENTATION PROCESSOR                              */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                    */
/* All rights reserved worldwide.  This is an unpublished work.           */
/* $Revision: 1.7.1.6 $                                                       */
/*V8:ConvertMode=Report                                                   */
/* REVISION: 7.4      LAST EDIT: 10/15/93      MODIFIED BY: pma *H013*    */
/* REVISION: 7.4      LAST EDIT: 07/13/95      MODIFIED BY: ais *H0FB*    */
/* REVISION: 7.4      LAST EDIT: 02/16/96      MODIFIED BY: rvw *H0JT*    */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98 BY: *L007* A. Rahane        */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98 BY: *K1Q4* Alfred Tan       */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98 BY: *J314* Alfred Tan       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00 BY: *N0KW* Jacolyn Neder    */
/* REVISION: 9.1      LAST MODIFIED: 08/24/00 BY: *N0MZ* Rajinder Kamra   */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.7.1.6 $    BY: Katie Hilbert         DATE: 12/27/02  ECO: *P0L8*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* DISPLAY TITLE */

/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "2+ "}

define new shared variable new_site like si_site.
define variable beg_yn        like mfc_logical label "Begin Implementation"
                              initial yes.
define variable nbr           like ecm_nbr label "Number".
define variable ecmid         like wo_lot  label "PCO ID".
define variable dbase         like si_db.
define variable dte_out       as date.
define variable dec_out       as integer.
define variable err_msg       like msg_nbr.
define variable msg           as character label "Message" format "x(20)".
define variable oldptrev      like pt_rev.
define variable error-msg-nbr like msg_nbr no-undo.
define variable unknown_char  as character initial ?.

define buffer psmstr for ps_mstr.
define buffer inmstr for in_mstr.
define buffer ecm1 for ecm_mstr.
define buffer ecm2 for ecm_mstr.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
beg_yn   colon 40
with frame a width 80 side-labels attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

repeat:

   update beg_yn with frame a.

   bcdparm = "".
   {mfquoter.i beg_yn  }

   if not beg_yn then do:
      pause 2 no-message.
      undo, retry.
   end.

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "printer"
               &printWidth = 132
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "yes"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.

   {mfphead.i}

   FORM /*GUI*/ 
      nbr
      ecmid
      dbase
      ecm_title
      ecm_eff_date
      ecd_part
      ecd_old_rev
      ecd_new_rev
      msg
   with STREAM-IO /*GUI*/  frame b width 132 down.

   /* SET EXTERNAL LABELS */
   setFrameLabels(frame b:handle).

   for each ecm_mstr no-lock
      where ecm_eff_date <> ? and ecm_eff_date <= today
        and ecm_end_date = ? and ecm_close_date = ?
      by ecm_eff_date
   with frame b width 132:
      
/*GUI*/ {mfguichk.i  &warn=false} /*Replace mfrpchk*/

      display
         space(5)
         substring(ecm_nbr,1,8)  @ nbr
         substring(ecm_nbr,9,8)  @ ecmid
         substring(ecm_nbr,17,8) @ dbase
         ecm_title
         ecm_eff_date
         getTermLabel("BEGIN_UPDATE",20) @ msg
      with frame b STREAM-IO /*GUI*/ .
      down.
      err_msg = 0.

      if not can-find (first ecd_det where ecd_nbr = ecm_nbr)
         then do for ecm1 transaction on error undo, next with frame b:

            find ecm1 exclusive-lock where recid(ecm1) = recid(ecm_mstr).
            assign
               ecm1.ecm_end_date   = today
               ecm1.ecm_close_date = today
               ecm1.ecm_replan     = no.

            display
               getTermLabel("CHANGES_COMPLETE",20) @ msg WITH STREAM-IO /*GUI*/ .

            err_msg = 0.

         end.

         ecd-loop1:
         for each ecd_det no-lock where ecd_nbr = ecm_nbr
               break by ecd_part with frame b:
            
/*GUI*/ {mfguichk.i  &warn=false} /*Replace mfrpchk*/


            do transaction on error undo, retry with frame b:
               display ecd_part WITH STREAM-IO /*GUI*/ .
               err_msg = 1.

               find pt_mstr exclusive-lock where pt_part = ecd_part
                  no-error.
               if not available pt_mstr then do:
                  err_msg = 16.
                  undo ecd-loop1, leave.
               end.

               display pt_rev @ ecd_old_rev WITH STREAM-IO /*GUI*/ .

               /* REVISION CHECKING NOW DONE BY ECREVCHK.P BELOW      */
               {gprun.i ""ecrevchk.p""
                  "(input pt_rev,
                    input ecd_new_rev,
                    output error-msg-nbr)"}

               if error-msg-nbr > 0 then err_msg = -1.

               oldptrev = pt_rev.

               /*UPDATE REVISION ETC*/
               assign
                  pt_rev       = ecd_new_rev
                  pt_draw      = ecd_draw
                  pt_drwg_loc  = ecd_drwg_loc
                  pt_drwg_size = ecd_drwg_size
                  pt_dsgn_grp  = ecd_dsgn_grp
                  pt_group     = ecd_group
                  pt_prod_line = ecd_prodline
                  pt_part_type = ecd_part_type
                  pt_status    = ecd_status
                  pt_mod_date  = today.
               if batchrun then
                  pt_userid = report_userid.
               else
                  pt_userid = global_userid.

               pt_mrp = yes.

               /*UPDATE PTP_DET RECORDS*/
               for each ptp_det exclusive-lock where ptp_part = pt_part:

                  if ptp_bom_code = pt_bom_code and
                     ptp_routing = pt_routing and
                     (ptp_rev = ? or ptp_rev = oldptrev)
                  then do:
                     assign
                        ptp_rev      = ecd_new_rev
                        ptp_mod_date = today.
                     if batchrun then
                        ptp_userid = report_userid.
                     else
                        ptp_userid = global_userid.
                     find in_mstr exclusive-lock
                        where in_part = ptp_part
                          and in_site = ptp_site
                     no-error.
                     if available in_mstr then in_mrp = yes.
                  end.
               end.

               /*SET REMAINING MRP FLAGS*/
               for each inmstr no-lock
                  where in_part = pt_part
                    and inmstr.in_mrp = no
                    and can-find (ptp_det where ptp_part = pt_part
                    and ptp_site = inmstr.in_site) = no:
                  do for in_mstr:
                     {inmrp.i &part=inmstr.in_part &site=inmstr.in_site}
                  end.
               end.

               display ecd_new_rev WITH STREAM-IO /*GUI*/ .

               /*UPDATE ECM_EFF_DATE*/
               if last(ecd_part) then do:
                  find ecm2 where recid(ecm2) = recid(ecm_mstr).
                  assign
                     ecm2.ecm_end_date   = today
                     ecm2.ecm_close_date = today
                     ecm2.ecm_replan     = no.

                  if err_msg = -1 then
                     display
                        caps(getTermLabel("WARNING",9)) + ": "
                        getTermLabel("REV_LEVEL",11)
                        format "x(20)" @ msg WITH STREAM-IO /*GUI*/ .
                  else
                     display
                        getTermLabel("CHANGES_COMPLETE",20) @ msg WITH STREAM-IO /*GUI*/ .
                  err_msg = 0.
               end.
               else do:
                  if err_msg = -1 then
                     display
                        caps(getTermLabel("WARNING",9)) + ": "
                        getTermLabel("REV_LEVEL",11)
                        format "x(20)" @ msg WITH STREAM-IO /*GUI*/ .
                  else
                     display
                        getTermLabel("OK",20) @ msg WITH STREAM-IO /*GUI*/ .
                  err_msg = 0.
                  down.
               end.
            end. /*do transaction*/
         end. /*for each ecd1_det*/

         if err_msg <> 0 then
            display
               getTermLabel("ERROR",8) + "# " + string(err_msg) @ msg
            with frame b STREAM-IO /*GUI*/ .
         down 2 with frame b.

      end. /*for each ecm_mstr*/

      
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


      /* REPORT TRAILER */
      {mfrtrail.i}

   end. /*repeat*/
